package com.yugao.fintech.antelope.base.config.remote;

import com.yugao.fintech.antelope.base.model.enums.ConfigDefineEnum;
import com.yugao.fintech.antelope.base.model.module.config.ConfigInfo;
import com.yugao.fintech.framework.assistant.utils.exception.BizException;
import com.yugao.fintech.framework.core.response.Resp;
import com.yugao.fintech.framework.core.response.RetOps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

@Service
@ConditionalOnClass({FeignAutoConfiguration.class})
public class ConfigManageApiCloudImpl implements ConfigManageApi {
    @Autowired
    @Lazy
    private RemoteConfigManage service;

    @Override
    @Async("myTaskScheduler")
    public Future<ConfigInfo> getUseConfig(ConfigDefineEnum configDefine) {
        Resp<ConfigInfo> rs = service.getUseConfig(configDefine.name());
        RetOps.of(rs).assertSuccess(e -> new BizException(e.getCode(), e.getMsg()));
        return new AsyncResult<>(rs.getData());
    }
}
